#ifndef DEVICE_GRAPHIC_DEVICE_H
#define DEVICE_GRAPHIC_DEVICE_H
#include "predefine.h"
#include "buffer.h"
#include "shader.h"
#include "igobject.h"
namespace Graphic
{	
	//////////////////////////////////////////////////////////////////////////
	enum PrimitiveType{
		PT_TRIANGLE,
		PT_TRIANGLE_FAN,
		PT_TRIANGLE_STRIP,
	};

	enum RenderStageType{
		RS_BLENDING,
		RS_DEPETH_TEST,
		RS_CULL_FACE,
		RS_WIREFRAME,
	};
	enum TextureFormat{
		TF_RGB,		TF_RGBA,	TF_BGRA,
		TF_DEPTH,	TF_DEPTH32,	TF_DEPTH16,
		TF_RED,		TF_GREEN,	TF_BLUE,	TF_ALPHA,
		TF_LUM,
	};
	enum ClearBufferBit
	{
		CB_CBUFFER = 0x001,		//color buffer
		CB_ZBUFFER = 0x010,		//depth buffer
		CB_SBUFFER = 0x100,		//stencil buffer
	};

	
	

	class DLL_EXPORT Device : public IGObject
	{
	public:
		virtual ~Device(){}
	public:
		virtual void Clear(int color = 0, int Buffers = CB_CBUFFER, float z = 1.0f, float stencil = 0.0f) = 0;
		virtual void Present(void* pSrcRect = 0, void*pDstRect = 0, void* hWindow = 0) = 0;
		virtual bool Begin() = 0;
		virtual void End() = 0;
	public://CreateObjects
		virtual ShaderProgram*	CreateShaderProgram(VertexShader* vs = 0, PixelShader* ps = 0) = 0;
		virtual VertexShader*	CreateVertexShader(const char* source) = 0;
		virtual PixelShader*	CreatePixelShader(const char* source) = 0;
		virtual VertexBuffer*	CreateVertexBuffer(int size, int usage, const char* data = 0) = 0;
		virtual IndexBuffer*	CreateIndexBuffer(int size, int usage, const char* data = 0) = 0;
		virtual Texture*		CreateTexture(int width, int height,  int iformat = TF_RGBA, int dformat = TF_BGRA, int dtype = DT_WORD, const char* data = 0) = 0;
		virtual FrameBuffer*	CreateFrameBuffer(int width, int height) = 0;
		
	public:
		virtual void SetVertexBuffer(int index, VertexBuffer* vb, int base = 0) = 0;
		virtual void SetIndexBuffer(IndexBuffer* ib) = 0;
		virtual void SetVertexDecl(VertexDecl* decl) = 0;

	public:
		virtual void Draw(int type, int begin, int count)					= 0;
		virtual void DrawIndexed(int type, int itype, int begin, int count) = 0;
		virtual void DrawRangeIndexed()	= 0;
		virtual void DrawIndexedBase() = 0;
		virtual void DrawRangeIndexedBase() = 0;

	public:
		virtual void SetRenderStage(int type, int val) = 0;
	};
	struct CreateParam
	{
		void* WindowHandle;
	};

	DLL_EXPORT Device* CreateDevice(const CreateParam& cp);
	DLL_EXPORT int GetARGB(int r, int g, int b, int a = 255);
	DLL_EXPORT int GetXRGB(int r, int g, int b);
};
#endif